package com.more.spring.boot.factory;

import com.more.spring.boot.pojo.User;
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;

import java.util.List;

public class CustomObjectFactory extends DefaultObjectFactory {
    @Override
    public <T> T create(Class<T> type) {

        if(type == User.class){
            return (T) new User(0, "defalut", "defalut");
        }
        return super.create(type);
    }

    @Override
    public <T> T create(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {

        if (type == User.class){
            return (T) new User((Integer) constructorArgs.get(0), (String)constructorArgs.get(1),(String) constructorArgs.get(3));
        }

        return super.create(type, constructorArgTypes, constructorArgs);
    }

}
